﻿Public Class frmMenu

    Public Sub CandidateManager()
        If My.Application.OpenForms.OfType(Of frmMain)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmMain.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmStaffManager)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmStaffManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageStaff)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmManageStaff.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageCandidates)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmManageCandidates.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmShiftManager)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmShiftManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendSMS)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmSendSMS.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageShifts)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmManageShifts.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmCandidateManager)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Hide()
            frmCandidateManager.Show()
        ElseIf My.Application.OpenForms.OfType(Of frmSendEmail)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmSendEmail.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSettings)().Any() Then
            'Loads frmCandidateManager
            frmCandidateManager.Show()
            frmSettings.Close()
        End If
    End Sub

    Public Sub StaffManager()
        If My.Application.OpenForms.OfType(Of frmMain)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmMain.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmCandidateManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmCandidateManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageCandidates)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmManageCandidates.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmShiftManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmShiftManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageStaff)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmManageStaff.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendSMS)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmSendSMS.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageShifts)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmManageShifts.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmStaffManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Hide()
            frmStaffManager.Show()
        ElseIf My.Application.OpenForms.OfType(Of frmSendEmail)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmSendEmail.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSettings)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmSettings.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmOvertimeManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmOvertimeManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmLeaveManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmLeaveManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmAttendanceManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmAttendanceManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmInfractionManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmInfractionManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmPaymentManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmPaymentManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmPayslipManager)().Any() Then
            'Loads frmStaffManager
            frmStaffManager.Show()
            frmPayslipManager.Close()
        End If
    End Sub

    Public Sub ShiftManager()
        If My.Application.OpenForms.OfType(Of frmMain)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmMain.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmCandidateManager)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmCandidateManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageCandidates)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmManageCandidates.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmStaffManager)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmStaffManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageStaff)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmManageStaff.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendSMS)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmSendSMS.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageShifts)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmManageShifts.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmShiftManager)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Hide()
            frmShiftManager.Show()
        ElseIf My.Application.OpenForms.OfType(Of frmSendEmail)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmSendEmail.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSettings)().Any() Then
            'Loads frmShiftManager
            frmShiftManager.Show()
            frmSettings.Close()
        End If
    End Sub

    Public Sub Settings()
        If My.Application.OpenForms.OfType(Of frmMain)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmMain.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmCandidateManager)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmCandidateManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageCandidates)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmManageCandidates.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmStaffManager)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmStaffManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageStaff)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmManageStaff.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendSMS)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmSendSMS.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmShiftManager)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmShiftManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageShifts)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmManageShifts.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendEmail)().Any() Then
            'Loads frmSettings
            frmSettings.Show()
            frmSendEmail.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSettings)().Any() Then
            'Loads frmSettings
            frmSettings.Hide()
            frmSettings.Show()
        End If
    End Sub

    Private Sub mnuExit_Click(sender As System.Object, e As System.EventArgs) Handles mnuExit.Click
        'Exit program
        Application.Exit()
    End Sub

    Private Sub btnCandidateManager_Click(sender As System.Object, e As System.EventArgs) Handles btnCandidateManager.Click
        CandidateManager()
    End Sub
    Private Sub btnStaffManager_Click(sender As System.Object, e As System.EventArgs) Handles btnStaffManager.Click
        StaffManager()
    End Sub

    Private Sub btnShiftManager_Click(sender As Object, e As EventArgs) Handles btnShiftManager.Click
        ShiftManager()
    End Sub

    Private Sub mnuAbout_Click(sender As Object, e As EventArgs) Handles mnuAbout.Click
        frmAbout.Show()
    End Sub

    Private Sub mnuMain_Click(sender As Object, e As EventArgs) Handles mnuMain.Click
        If My.Application.OpenForms.OfType(Of frmMain)().Any() Then
            'Loads frmMain
            frmMain.Hide()
            frmMain.Show()
        ElseIf My.Application.OpenForms.OfType(Of frmCandidateManager)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmCandidateManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageCandidates)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmManageCandidates.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmStaffManager)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmStaffManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageStaff)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmManageStaff.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendSMS)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmSendSMS.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmShiftManager)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmShiftManager.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmManageShifts)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmManageShifts.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSendEmail)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmSendEmail.Close()
        ElseIf My.Application.OpenForms.OfType(Of frmSettings)().Any() Then
            'Loads frmMain
            frmMain.Show()
            frmSettings.Close()
        End If
    End Sub

    Private Sub btnSettings_Click(sender As Object, e As EventArgs) Handles btnSettings.Click
        Settings()
    End Sub

    Private Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
        Settings()
    End Sub

    Private Sub btnCanManager_Click(sender As Object, e As EventArgs) Handles btnCanManager.Click
        CandidateManager()
    End Sub

    Private Sub btnStaManager_Click(sender As Object, e As EventArgs) Handles btnStaManager.Click
        StaffManager()
    End Sub

    Private Sub btnShiManager_Click(sender As Object, e As EventArgs) Handles btnShiManager.Click
        ShiftManager()
    End Sub
End Class